


class AsyncOperation(object):

    def __init__(self, type_, handle):
        self._type = type_
        self._handle = handle


    def type_(self):
        return self._type


    def handle(self):
        return self._handle


    def exec_(self):
        raise NotImplementedException, "subclass responsibility"



class AcceptOperation(AsyncOperation):

    def __init__(self, handle):
        AsyncOperation.__init__(self, "accept", handle)


    def exec_(self):
        return self._handle.accept()



class ConnectOperation(AsyncOperation):

    def __init__(self, handle, remote_address):
        AsyncOperation.__init__(self, "connect", handle)
        self._remote_address = remote_address


    def exec_(self):
        return self._handle.connect(self._remote_address)



class RecvOperation(AsyncOperation):

    def __init__(self, handle, cnt):
        AsyncOperation.__init__(self, "recv", handle)
        self._cnt = cnt


    def exec_(self):
        return self._handle.recv(self._cnt)



class SendOperation(AsyncOperation):

    def __init__(self, handle, buf):
        AsyncOperation.__init__(self, "send", handle)
        self._buf = buf


    def exec_(self):
        return self._handle.send(self._buf)
